package com.yjj.demo.spring.redis.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 *
 *
 * @author yangjiajia
 * @createdAt 2023/2/6 17:27
 */
@Service
public class ZSetService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public void add(String key, String member, double score) {
        stringRedisTemplate.opsForZSet().add(key, member, score);
    }

    public Set<String> list(String key) {
        return stringRedisTemplate.opsForZSet().range(key, 0, -1);
    }

    public Set<String> reserveList(String key) {
        return stringRedisTemplate.opsForZSet().reverseRange(key, 0, -1);
    }

    public long getScore(String key, String member) {
        return stringRedisTemplate.opsForZSet().rank(key, member);
    }

}
